package com.wxw.BaseLibrary.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import com.wxw.BaseLibrary.element.IListBoxItem;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by david on 2014-07-14.
 */
public class ListBoxAdapter<T extends IListBoxItem> extends BaseAdapter {
    protected List<T> items = new ArrayList<T>();
    protected Context context;

    public ListBoxAdapter(Context context, List<T> items){
        this.context = context;
        if (items!=null) {
            this.items = items;
        }
    }
    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public Object getItem(int position) {
        return position >= 0 && items.size() > 0 && items.size() > position ? items.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (position < 0 || items.size() <= 0 || items.size() > position) {
            return null;
        }
        return items.get(position).getView();
    }
}
